<?php
require_once "../includes/config.php";

if(isset($_REQUEST['keyword']))
{
		$subcatId=$_REQUEST['scat_id'];
		if($subcatId!="") {		
			$sscatname=$_REQUEST['subcat_name'];
			$subcatDescription=$_REQUEST['subcat_description'];		
			$today=date("Y-m-d");		
			$sql_addcat="INSERT INTO tbl_category SET parent_id=$subcatId, category_name='$sscatname',category_description='$subcatDescription', created_date='$today'";
			$rst_addcat=mysql_query($sql_addcat);
			$catImageIns=mysql_insert_id();	
			if($catImageIns>0) {
				$msgAddScat="Sub-subcategory added Successfully";				
			}
		}
}
?>
<script type="text/javascript">
	function funValSubSubcat() {
		var scatid = document.getElementById('scat_id');
		var subcatname = document.getElementById('subcat_name');
		var subcatdesc = document.getElementById('subcat_description');
		if(scatid.value=="") {
			alert("Select Subcategory");
			scatid.focus();
			return false;
		}
		if(subcatname.value=="") {
			alert("Enter Sub-Sub Category name");
			subcatname.focus();
			return false;			
		}
		if(subcatdesc.value=="") {
			alert("Enter Sub-Sub Category description");
			subcatdesc.focus();
			return false;
		}
		return true;
	}
</script>

<form action="" method="post" name="form1" id="form1" onsubmit="return funValSubSubcat();">
<input type="hidden" name="keyword" id="keyword">
<table width="100%"  border="1" cellspacing="0" class="container">
  <tr>
    <td width="469" height="25" class="tdHeader">Add Sub-Subcategory</td>
  </tr>  
  <tr>
    <td height="577">
	<br><br>			  
           <table width="423" height="265" border="0" cellspacing="0">
          <tr>
            <td colspan="3"><div align="center"><?php echo "<b>".$msgAddScat."</b>"; ?></div></td>            
          </tr>
          <tr>
            <td height="29">&nbsp;</td>
            <td><div align="left">Category Name </div></td>
            <td>
              <div align="left">
				<select name="cat_id" id="cat_id" onChange='window.location="index.php?addsscat&cat="+this.value;' class="fieldMax1">
				              <option value="">..Select Category..</option> 
			   <?php			   
			   $sqlSelCategory="SELECT * FROM tbl_category where parent_id=0";
			   $rstSelCategory=mysql_query($sqlSelCategory);
			   while($rowSelCategory=mysql_fetch_array($rstSelCategory))
			   {
			   $categoryId=$rowSelCategory['category_id'];
			   $categoryName=$rowSelCategory['category_name'];
					 if(!empty($_REQUEST['cat'])) {
							if($categoryId==$_REQUEST['cat']) {
									$select="selected";
							} else {
									$select="";
							}
						} else { $select=""; }
					   
					   echo "<option value='$categoryId' $select>$categoryName</option>";
			   }
			   ?>			  
               </select>
              </div></td>
          </tr>
		   <?php 
		   
		   $catId=$_REQUEST['cat'];		   
		   $sqlSelsubCategory="SELECT * FROM tbl_category where parent_id=$catId";
		   $rstSelsubCategory=mysql_query($sqlSelsubCategory);
		  
		  ?>
		  <tr>
		    <td height="29">&nbsp;</td>
		    <td>SubCategory Name </td>
		    <td><div align="left">
				<select name="scat_id" id="scat_id" class="fieldMax1">
				   <option value="">..Select Subcategory..</option> 
			   <?php	
			  
			   while($rowSelsubCategory=mysql_fetch_array($rstSelsubCategory))
			   {
			   $subcategoryId=$rowSelsubCategory['category_id'];
			   $subcategoryName=$rowSelsubCategory['category_name'];
			   
			     if(!empty($_REQUEST['cat'])) {						
						if($subcategoryId==$_REQUEST['scat']) {
								$sel="selected";
						} else {
								$sel="";
						}
					} else { $sel=""; } 
					 
				   echo "<option value='$subcategoryId' $sel>$subcategoryName</option>";
			   }
			   ?>
               </select>
              </div></td>
		    </tr>
		
		  <tr>
            <td height="29">&nbsp;</td>
            <td>Sub-subcategory Name</td>
            <td>             
                <input type="text" name="subcat_name" id="subcat_name">
              </td>
          </tr>  

          <tr>
            <td height="31">&nbsp;</td>
            <td>Sub-subcategory Description </td>
            <td><input type="text" name="subcat_description" id="subcat_description"></td>
          </tr>
		  	  
          <tr>
            <td height="65" colspan="3"><div align="center">
                <input name="submit" type="submit" id="submit" value="Add Sub-subCategory" class="button">
              </div></td>
            </tr>
        </table>
      
      </td>
  </tr>
</table>
 </form>

